//
//  GMUIHelper.m
//  gentleman
//
//  Created by 范月成 on 2017/12/5.
//  Copyright © 2017年 fancy. All rights reserved.
//

#import "GMUIHelper.h"

@implementation GMUIHelper

+ (YYLabel *)labelWithFont:(UIFont *)font
                 textColor:(UIColor *)textColor {
    YYLabel *label = [[YYLabel alloc] init];
    label.font = font;
    label.textColor = textColor;
    return label;
}

+ (YYLabel *)generalTitleLabel {
    return [GMUIHelper labelWithFont:kSystemBoldFont(16) textColor:[UIColor themeBlack]];
}

+ (YYLabel *)generalSubTitleLabel {
    return [GMUIHelper labelWithFont:kSystemFont(14) textColor:[UIColor themeGray]];
}

+ (UIButton *)buttonWithFont:(UIFont *)font
                  titleColor:(UIColor *)titleColor {
    UIButton *button = [[UIButton alloc] init];
    button.titleLabel.font = font;
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    return button;
}

+ (UIAlertController *)alertWithTitle:(NSString *)title
                              message:(NSString *)message {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    [[UIViewController currentViewController] presentViewController:alert animated:YES completion:nil];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [alert dismissViewControllerAnimated:YES completion:nil];
    });
    return alert;
}

+ (UIAlertController *)alertWithTitle:(NSString *)title
                              message:(NSString *)message
                               ensure:(void (^)(void))ensure
                               cancel:(void (^)(void))cancel {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        !ensure?:ensure();
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        !cancel?:cancel();
    }]];
    
    [[UIViewController currentViewController] presentViewController:alert animated:YES completion:nil];
    
    return alert;
}

@end
